package com.ruipengkj.component.jtable;

import java.awt.BorderLayout;
import java.awt.Color;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableModel;

import com.ruipengkj.commons.util.Util;
import com.ruipengkj.model.MemberConsumptionModel;

public class RPTable extends JTable {

	private static final long serialVersionUID = 1L;
	private Color verticalGridColor = Color.white;
    private RPTableCellRenderer renderer = new RPTableCellRenderer();
    private RPTableHeaderRenderer headerRenderer = new RPTableHeaderRenderer();

	public RPTable(TableModel dm) {
		super(dm);
		init();
	}

	public static void main(String[] args) {
		JFrame jf=new JFrame();
		JPanel jp=new JPanel(new BorderLayout());
		jp.setBackground(Color.RED);
		jf.add(jp);
		
		jp.add(new RPTable(new MemberConsumptionModel(null)));
		jf.setSize(400, 400);
		jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		jf.setVisible(true);
	}
	

    private void init() {
        this.setFont(Util.FONT_12_PLAIN);
        this.getTableHeader().setFont(Util.FONT_12_BOLD);
        this.getTableHeader().setDefaultRenderer(headerRenderer);
        this.setBorder(null);
        this.setRowSelectionAllowed(true);
        this.setShowHorizontalLines(false);
        this.setShowVerticalLines(true);
        this.setGridColor(verticalGridColor);
        this.setRowMargin(0);
        this.setOpaque(false);
    }

    @Override
    public TableCellRenderer getCellRenderer(int row, int column) {
//    	if (column == 0)
//    		return super.getCellRenderer(row, column);
        return renderer;
    }
//    @Override
//	public Component prepareRenderer(TableCellRenderer renderer, int row,
//			int column) {
//    	Component c = super.prepareRenderer(renderer, row, column);
//		if (c instanceof JComponent) {
//			((JComponent) c).setOpaque(false);
//		}
//		return c;
//	}
//    @Override
//    public boolean isCellEditable(int row, int column) {
//        return false;
//    }
}
